<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
$store_id=$this->session('store_id');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['banner']=$basic['image'];
if($_RQ['op']=='list'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'status'=>1,
	);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_qiuyuyue_timeserve',$params,array($pindex,$psize),$total,array(),'','paixu desc, id desc');
	foreach($list as &$item){
		//已支付，已确认，已完成订单数
		$server=$this->pdo_get('serve',array('id'=>$item['serve_id']));
		$item=array_merge($server,$item);
		$item['num']=pdo_count('jy_qiuyuyue_timeserve_order',array('uniacid'=>$_SESSION['uniacid'],'goods_id'=>$item['id'],'status >='=>'1'));
	}
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	$return['post']=array();
	$return['list']=$list;
	$return['sharedata']=array(
			'title'=>'项目列表',
			'desc'=>$basic['share_desc']?:'上门服务，技师入驻，经络排毒，活血化瘀！',
			'link'=>custom_url('jy_qiuyuyue/server//fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
if($_RQ['op']=='sever_detail'){
	if(!$_RQ['id']){
		exi('没有找到该项目！','error');
	}
	//查询项目具体信息
	$timeserve=pdo_get('jy_qiuyuyue_timeserve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	$serve=pdo_get('jy_qiuyuyue_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$timeserve['serve_id']));
	$package=$serve['package'];
	//查询本项目可服务员工(未锁定，状态为可服务)
	$worker_list=pdo_getall('jy_qiuyuyue_store_worker',array('uniacid'=>$_SESSION['uniacid'],'islock'=>'0','status'=>'1'));
	foreach($worker_list as $k=>$item){
		$service=explode(";",$item['service']);
		if(!in_array($_RQ['id'],$service)){
			unset($worker_list[$k]);
		}
	}
	//查询自定义字段
	$fileds=$serve['fileds']?json_decode($serve['fileds']):array();
	//查询本项目的访问人数及添加访问人数
	$num=pdo_getcolumn('jy_qiuyuyue_serve',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']),'num');
	$serve['num']=$num+1;
	pdo_update('jy_qiuyuyue_serve',array('num'=>$serve['num']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	//已支付，已确认，已完成订单数
	$timeserve['ordernum']=pdo_count('jy_qiuyuyue_timeserve_order',array('uniacid'=>$_SESSION['uniacid'],'goods_id'=>$_RQ['id'],'status >='=>'1'));
	$serve_time=json_decode($serve['serve_time'],true);
	//日期 今天，未来七天
	$data=array();
	$weekarray=array("日","一","二","三","四","五","六"); //先定义一个数组
	$days=$basic['days']>0?$basic['days']:7;
	for($i=0;$i<6;$i++){
		$iswork=strpos($serve['work_time'],';'.$i.';');	
		$data[]=array(
			'riqi'=>date("m-d",strtotime("+".$i." day")),
			'xinq'=>"星期".$weekarray[$i],
			'iswork'=>$iswork
		);
	}
	$serve['package']=json_decode($serve['package'],true);
	$serve['hdps']=json_decode($serve['hdps'],true);
	$timeserve['hdps']=json_decode($timeserve['hdps'],true);
	$timeserve['oldprice']=price($serve['price']*$timeserve['times']);
	$return['serve']=$serve;
	$return['timeserve']=$timeserve;
	$return['package']=json_decode($package);
	$return['worker_list']=$worker_list;
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['data']=$data;
	$return['post']=array(
		'dayid'=>0,
		'store_id'=>$store_id,
		'packageid'=>0,
	);
	$return['post']['fileds']=$fileds;
	$return['sharedata']=array(
			'title'=>'项目-'.$serve['title'],
			'desc'=>$serve['remark']?:'上门服务，技师入驻，经络排毒，活血化瘀！',
			'link'=>custom_url('jy_qiuyuyue/timeserver/detail/id='.$serve['id'].'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
			'imgUrl'=>ATTACHMENT_URL.$serve['image'],
	);
	exi($return);
}
if($_RQ['op']=='check_buy'){
	$store_id=$_RQ['store_id']?:$store_id;
	exi('','','jy_qiuyuyue/timesbook//store_id='.$store_id.'&serve_id='.$_RQ['serve_id']);
}
